
use serde::{Serialize, Serializer};
use std::{collections::HashMap, sync::Mutex};
use tauri::Manager;
use tauri::{command, AppHandle, Runtime, State, Window};

use model_graph_types::{
    connector::{Connector, ExecuteOptions, QueryOptions},
    database::{DataSource, DatabaseType},
    modeling::Value,
};
use serde_json::Value as JsonValue;
use union_connector::UnionConnector;

use model_graph_common::{transport::http::http_download_file, utils::zip::extract_v8_to_fs};

#[tauri::command]
pub fn eval<R: Runtime>(self_window: Window<R>, window: String, script: String) -> (i32, String) {
    let target_window_option = self_window.get_webview_window(window.as_str());

    match target_window_option {
        Some(win) => {
            tracing::debug!("window:{},script:{}", window, script);
            let _ = win.eval(format!("{}", script).as_str());
            (0, String::from("成功"))
        }
        None => (1, String::from("没有找到Window!")),
    }
}

#[tauri::command]
pub fn window_set_url<R: Runtime>(self_window: Window<R>, url: String) -> (i32, String) {
    let target_window_option = self_window.get_webview_window(self_window.label());
    match target_window_option {
        Some(win) => {
            tracing::debug!("url:{}", url);
            let _ = win.eval(format!("window.location.replace('{}')", url).as_str());
            (0, String::from("成功"))
        }
        None => (1, String::from("没有找到Window!")),
    }
}
